{
  "properties" : { },
  "id" : "copy1736472412051d55087",
  "script" : null,
  "groupId" : "b49fd3aa7ab944ca938fd37f3364f0ba",
  "name" : "B7查询气象站历史天气坐标查询",
  "createTime" : null,
  "updateTime" : 1736473037595,
  "lock" : null,
  "createBy" : "admin",
  "updateBy" : "admin",
  "path" : "/wsstationweathernearesthis",
  "method" : "GET",
  "parameters" : [ {
    "name" : "time",
    "value" : "",
    "description" : "数据可以按找小时获取  yyyy-MM-ddTHH:00:00   不填写取最终数据",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "lon",
    "value" : "126.35",
    "description" : "经度",
    "required" : true,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "lat",
    "value" : "43.56",
    "description" : "纬度",
    "required" : true,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "maxdislimit",
    "value" : "100",
    "description" : "最大距离限制 超过距离数据无法查询 不传不限制数据",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "stationtype",
    "value" : null,
    "description" : "站点类型  1. 国家站  2. 区域站 3. 火险监测站(海康)  4:和风天气",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "btime",
    "value" : "2024-12-20T00:00:00",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "etime",
    "value" : "2025-01-03T00:00:00",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "page",
    "value" : "1",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "size",
    "value" : "20",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "hour",
    "value" : "15",
    "description" : null,
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 0,\n    \"message\": \"success\",\n    \"data\": {\n        \"total\": 118,\n        \"list\": [\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-02T15:58:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -13,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 69,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 11,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 23:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-02T13:58:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -13,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 66,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 8,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 21:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-02T11:58:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -16,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 72,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 180,\n                \"win_10_vel\": 2,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 19:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-02T09:54:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -10,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 64,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 10,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 17:54:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-02T07:50:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -8,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 44,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 13,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 15:50:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-02T05:58:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -7,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 40,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 270,\n                \"win_10_vel\": 12,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 13:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-02T03:44:00.000+00:00\",\n                \"pres\": 996,\n                \"pres_sea\": null,\n                \"temp\": -8,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 47,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 270,\n                \"win_10_vel\": 14,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 11:44:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-02T01:58:00.000+00:00\",\n                \"pres\": 996,\n                \"pres_sea\": null,\n                \"temp\": -10,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 56,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 17,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 09:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T23:58:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -12,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 72,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 270,\n                \"win_10_vel\": 7,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"雾\",\n                \"time\": \"2025-01-02 07:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T21:56:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -13,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 74,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 180,\n                \"win_10_vel\": 6,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"雾\",\n                \"time\": \"2025-01-02 05:56:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T19:58:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -14,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 83,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 5,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 03:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T17:58:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -15,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 84,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 3,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-02 01:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T15:58:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -16,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 86,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 180,\n                \"win_10_vel\": 2,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"雾\",\n                \"time\": \"2025-01-01 23:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T13:58:00.000+00:00\",\n                \"pres\": 995,\n                \"pres_sea\": null,\n                \"temp\": -12,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 84,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 180,\n                \"win_10_vel\": 4,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"雾\",\n                \"time\": \"2025-01-01 21:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T11:48:00.000+00:00\",\n                \"pres\": 994,\n                \"pres_sea\": null,\n                \"temp\": -13,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 77,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 180,\n                \"win_10_vel\": 7,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"雾\",\n                \"time\": \"2025-01-01 19:48:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T09:56:00.000+00:00\",\n                \"pres\": 993,\n                \"pres_sea\": null,\n                \"temp\": -8,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 59,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 8,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-01 17:56:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T07:58:00.000+00:00\",\n                \"pres\": 993,\n                \"pres_sea\": null,\n                \"temp\": -6,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 46,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 270,\n                \"win_10_vel\": 7,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-01 15:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T05:58:00.000+00:00\",\n                \"pres\": 992,\n                \"pres_sea\": null,\n                \"temp\": -5,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 43,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 16,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-01 13:58:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T03:56:00.000+00:00\",\n                \"pres\": 993,\n                \"pres_sea\": null,\n                \"temp\": -7,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 48,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 23,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-01 11:56:00\"\n            },\n            {\n                \"stationkey\": \"101060203\",\n                \"timebase\": \"2025-01-01T01:58:00.000+00:00\",\n                \"pres\": 992,\n                \"pres_sea\": null,\n                \"temp\": -8,\n                \"temp_max\": null,\n                \"temp_min\": null,\n                \"humi\": 51,\n                \"humi_min\": null,\n                \"prec\": 0,\n                \"win_10_dir\": 225,\n                \"win_10_vel\": 14,\n                \"win_inst_dir\": null,\n                \"win_inst_vel\": null,\n                \"snow\": null,\n                \"wep_now\": null,\n                \"month\": \"202501\",\n                \"wep_txt\": \"晴\",\n                \"time\": \"2025-01-01 09:58:00\"\n            }\n        ]\n    },\n    \"timestamp\": 1736473019142,\n    \"executeTime\": 421\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : null
}
================================
/**
 *   按照机构号码查询、
 *  @param   orgid  系统机构
 *  @param   time        时间格式数据可以按找小时获取  yyyy-MM-ddTHH:00:00   不传查最新 传查指定时间  必须传入整点数据
 *  @param   lon  lat 坐标
 * 
 *     
     left join fx_station_norainday nr on  nr.stationkey = t1.stationkey and DATE(t1.timeBase) = nr.date
 */
import com.mingda.weathermagiccenter.utils.WeatherDeal;
import 'java.lang.System' as System;
var sql = """
with
cr as
( select distinct ws_station.* from ws_station,ws_station_data
where  ws_station.stationkey = ws_station_data.stationkey
    <if test="time != null and time != ''\" > and TO_TIMESTAMP(replace(#{time},'T',' '), 'YYYY-MM-DD HH24:MI:SS') = ws_station_data.timebase </if>
    <else>and date(ws_station_data.timebase) = CURRENT_DATE</else>
) 
    select stationkey,  ST_Distance( ST_MakePoint(CAST(lon AS float8), CAST(lat AS float8))::geography,  ST_MakePoint(CAST(#{lon} AS float8),CAST(#{lat} AS float8))::geography )  AS distance
    from cr  
    where 1 = 1 
     <if test="stationtype != null and stationtype != ''" > and stationtype = #{stationtype} </if>
     <if test="maxdislimit != null and maxdislimit != ''\" > 
     and   ST_Distance( ST_MakePoint(CAST(lon AS float8), CAST(lat AS float8))::geography,  ST_MakePoint(CAST(#{lon} AS float8),CAST(#{lat} AS float8))::geography )  <=
      CAST(#{maxdislimit} AS float8) * 1000
      </if>
    order by distance 
    LIMIT 1
     ;
"""
 

 var nereststation = [];
 //var distance ="";
//查询最近的站点
 var result =  db.select (sql);
 if(result.size() > 0){

     for(item in result){
        nereststation.add(item.stationkey);
     }
     System.out.println("------------------"+nereststation);
     // distance =  result.get(0).distance;
 }
 else{
     return null;
 }








// 获得最近气象站点的数据 ,${distance} as distance
var sql2 = """

    select  *,to_char(timebase, 'YYYY-MM-DD HH24:MI:SS') as time from ws_station_data   
    where 1 = 1 
        and stationKey in 
    <foreach collection="nereststation" item="id" open="(" close=")" separator=",">
		'${id}'
    </foreach>
     <if test="btime != null and btime != ''\" > and TO_TIMESTAMP(replace(#{btime},'T',' '), 'YYYY-MM-DD HH24:MI:SS') <= timeBase </if>
     <if test="etime != null and etime != ''\" > and TO_TIMESTAMP(replace(#{etime},'T',' '), 'YYYY-MM-DD HH24:MI:SS') >= timeBase </if>
     <if test="hour != null and hour != ''\" > and  EXTRACT(HOUR FROM timebase) = ${hour}  </if>
     order by timeBase  desc
"""
return db.page(sql2);
 

 